home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / bsd / netinet / in_var.h < prev    next >
C/C++ Source or Header  |  1995-02-14  |  6KB  |  174 lines

  1. /*
  2.  * Copyright (c) 1985, 1986 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that this notice is preserved and that due credit is given
  7.  * to the University of California at Berkeley. The name of the University
  8.  * may not be used to endorse or promote products derived from this
  9.  * software without specific prior written permission. This software
  10.  * is provided ``as is'' without express or implied warranty.
  11.  *
  12.  *    @(#)in_var.h    7.2 (Berkeley) 12/7/87
  13.  */
  14. /* HISTORY
  15.  * 11-Jul-93   Mac Gillon (mgillon) at NeXT
  16.  *     Integrated MULTICAST support
  17.  */
  18.  
  19. /*
  20.  * Interface address, Internet version.  One of these structures
  21.  * is allocated for each interface with an Internet address.
  22.  * The ifaddr structure contains the protocol-independent part
  23.  * of the structure and is assumed to be first.
  24.  */
  25. struct in_ifaddr {
  26.     struct ifaddr ia_ifa;            /* protocol-independent info */
  27. #define    ia_addr    ia_ifa.ifa_addr
  28. #define    ia_broadaddr ia_ifa.ifa_broadaddr
  29. #define    ia_dstaddr ia_ifa.ifa_dstaddr
  30. #define    ia_ifp ia_ifa.ifa_ifp
  31.     u_long ia_net;                    /* network number of interface */
  32.     u_long ia_netmask;                /* mask of net part */
  33.     u_long ia_subnet;                /* subnet number, including net */
  34.     u_long ia_subnetmask;            /* mask of net + subnet */
  35.     struct in_addr ia_netbroadcast; /* broadcast addr for (logical) net */
  36.     int    ia_flags;
  37.     struct in_ifaddr *ia_next;        /* next in list of internet addresses */
  38. #ifdef MULTICAST
  39.     struct in_multi *ia_multiaddrs;    /* list of multicast addresses */
  40. #endif
  41. };
  42.  
  43. /*
  44.  * Given a pointer to an in_ifaddr (ifaddr),
  45.  * return a pointer to the addr as a sockadd_in.
  46.  */
  47. #define    IA_SIN(ia) ((struct sockaddr_in *)(&((struct in_ifaddr *)ia)->ia_addr))
  48. /*
  49.  * ia_flags - Note these flags move into *ia_ifa in net2 (and 4.4) release
  50.  */
  51. #define    IFA_ROUTE 0x01                /* routing entry installed */
  52. #define    IFA_NETMASK_AUTH 0x02        /* authoritative ICMP netmask server */
  53. #define    IFA_AWAITING_MASK 0x04        /* ready to accept netmask reply */
  54.  
  55. #ifdef    KERNEL
  56. struct    in_ifaddr *in_ifaddr;
  57. struct    in_ifaddr *in_iaonnetof();
  58. struct    ifqueue    ipintrq;        /* ip packet input queue */
  59. #endif
  60.  
  61. #ifdef KERNEL
  62. /*
  63.  * Macro for finding the interface (ifnet structure) corresponding to one
  64.  * of our IP addresses.
  65.  */
  66. #define INADDR_TO_IFP(addr, ifp) \
  67.     /* struct in_addr addr; */ \
  68.     /* struct ifnet *ifp;  */ \
  69. { \
  70.     register struct in_ifaddr *ia; \
  71.     for (ia = in_ifaddr; \
  72.          ia != NULL && IA_SIN(ia)->sin_addr.s_addr != (addr).s_addr; \
  73.          ia = ia->ia_next); \
  74.     (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
  75. }
  76.  
  77. /*
  78.  * Macro for finding the internet address structure (in_ifaddr) corresponding
  79.  * to a given interface (ifnet structure).
  80.  */
  81. #define IFP_TO_IA(ifp, ia) \
  82.     /* struct ifnet     *ifp; */ \
  83.     /* struct in_ifaddr *ia;  */ \
  84. { \
  85.     for ((ia) = in_ifaddr; \
  86.          (ia) != NULL && (ia)->ia_ifp != (ifp); \
  87.          (ia) = (ia)->ia_next); \
  88. }
  89. #endif KERNEL
  90.  
  91. #ifdef MULTICAST
  92. /*
  93.  * Internet multicast address structure.  There is one of these for each IP
  94.  * multicast group to which this host belongs on a given network interface.
  95.  * They are kept in a linked list, rooted in the interface's in_ifaddr
  96.  * structure.
  97.  */
  98. struct in_multi {
  99.     struct in_addr      inm_addr;    /* IP multicast address             */
  100.     struct ifnet     *inm_ifp;    /* back pointer to ifnet            */
  101.     struct in_ifaddr *inm_ia;    /* back pointer to in_ifaddr        */
  102.     u_int          inm_refcount;    /* no. membership claims by sockets */
  103.     u_int          inm_timer;    /* IGMP membership report timer     */
  104.     struct in_multi  *inm_next;    /* ptr to next multicast address    */
  105. };
  106.  
  107. #ifdef KERNEL
  108. /*
  109.  * Structure used by macros below to remember position when stepping through
  110.  * all of the in_multi records.
  111.  */
  112. struct in_multistep {
  113.     struct in_ifaddr *i_ia;
  114.     struct in_multi  *i_inm;
  115. };
  116.  
  117. /*
  118.  * Macro for looking up the in_multi record for a given IP multicast address
  119.  * on a given interface.  If no matching record is found, "inm" returns NULL.
  120.  */
  121. #define IN_LOOKUP_MULTI(addr, ifp, inm)                \
  122.     /* struct in_addr  addr; */                        \
  123.     /* struct ifnet    *ifp; */                        \
  124.     /* struct in_multi *inm; */                        \
  125. {                                                    \
  126.     register struct in_ifaddr *ia;                    \
  127.     IFP_TO_IA((ifp), ia);                            \
  128.     if (ia == NULL)                                    \
  129.         (inm) = NULL;                                \
  130.     else                                            \
  131.         for ((inm) = ia->ia_multiaddrs;                \
  132.          (inm) != NULL && (inm)->inm_addr.s_addr != (addr).s_addr;  \
  133.          (inm) = inm->inm_next);                    \
  134. }
  135.  
  136. /*
  137.  * Macro to step through all of the in_multi records, one at a time.
  138.  * The current position is remembered in "step", which the caller must
  139.  * provide.  IN_FIRST_MULTI(), below, must be called to initialize "step"
  140.  * and get the first record.  Both macros return a NULL "inm" when there
  141.  * are no remaining records.
  142.  */
  143. #define IN_NEXT_MULTI(step, inm)                    \
  144.     /* struct in_multistep  step; */                \
  145.     /* struct in_multi     *inm;  */                \
  146. {                                                    \
  147.     if (((inm) = (step).i_inm) != NULL) {            \
  148.         (step).i_inm = (inm)->inm_next;                \
  149.     }                                                \
  150.     else while ((step).i_ia != NULL) {                \
  151.         (inm) = (step).i_ia->ia_multiaddrs;            \
  152.         (step).i_ia = (step).i_ia->ia_next;            \
  153.         if ((inm) != NULL) {                        \
  154.             (step).i_inm = (inm)->inm_next;            \
  155.             break;                                    \
  156.         }                                            \
  157.     }                                                \
  158. }
  159.  
  160. #define IN_FIRST_MULTI(step, inm, ia)                \
  161.     /* struct in_multistep  step; */                \
  162.     /* struct in_multi     *inm;  */                \
  163.     /* struct in_ifaddr        *ia;  */                \
  164. {                                                    \
  165.     (step).i_ia  = ia;                                \
  166.     (step).i_inm = NULL;                            \
  167.     IN_NEXT_MULTI((step), (inm));                    \
  168. }
  169.  
  170. struct in_multi *in_addmulti();
  171.  
  172. #endif KERNEL
  173. #endif MULTICAST
  174.